package com.vip.iot.entity;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.annotation.JSONField;
import com.vip.iot.service.MqttSubMsgService;
import com.vip.iot.util.CommonUtils;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

/**
 * MQTT响应手环定位数据的实体类
 *
 * @author wgb
 * @Date 2019/3/14
 */
@Data
public class HandleRingInfo {

    /**
     * 场景id
     */
    @JSONField(name = "scene_id")
    private int sceneId;
    /**
     * 建筑id
     */
    @JSONField(name = "building_id")
    private int buildingId;
    /**
     * 楼层id
     */
    @JSONField(name = "floor_id")
    private int floorId;
    /**
     * 小区
     */
    @JSONField(name = "subnet_id")
    private int subnetId;
    /**
     * 手环的X坐标
     */
    @JSONField(name = "card_x")
    private double cardX;
    /**
     * 手环的Y坐标
     */
    @JSONField(name = "card_y")
    private double cardY;
    /**
     * 手环的Z坐标
     */
    @JSONField(name = "card_z")
    private double cardZ;
    /**
     * 手环ID
     */
    @JSONField(name = "card_id")
    private int cardId;
    /**
     * 时间戳
     */
    private long time;
    /**
     * 手环相对Z坐标
     */
    @JSONField(name = "card_relative_z")
    private double cardRelativeZ;
    /**
     * 服务端响应毫秒时间戳
     */
    @JSONField(name = "rec_server_time_ms")
    private int recServerTimeMs;
    /**
     * 服务端响应秒时间戳
     */
    @JSONField(name = "rec_server_time")
    private int recServerTime;

    public HandleRingInfo() {
    }

    public HandleRingInfo(int cardId, double cardX, double cardY, double cardZ, double cardRelativeZ, long time, int sceneId, int floorId, int subnetId) {
        this.cardId = cardId;
        this.cardX = cardX;
        this.cardY = cardY;
        this.cardZ = cardZ;
        this.cardRelativeZ = cardRelativeZ;
        this.time = time;
        this.sceneId = sceneId;
        this.floorId = floorId;
        this.subnetId = subnetId;
    }

    /**
     * 生成10条数据
     *
     * @return
     */
    public static String createHandleRingInform() {
        List<HandleRingInfo> data = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            MqttSubMsgService service = new MqttSubMsgService();
            HandleRingInfo hri = new HandleRingInfo(i * 26 + 200, 1.065071420578165 + i * 20, 3.208563254909678 + i * 10, 6.5, 1.5, 1522303840747L, 1, 1, 1);
            Vector3D lonlatSource = service.locationSourceToVector3D("109.598480,22.8744160,0.0");
            Vector3D mercator = CommonUtils.lonLat2Mercator(lonlatSource);
            mercator.setX(mercator.getX() + hri.getCardX());
            mercator.setY(mercator.getY() + hri.getCardY());
            mercator.setZ(mercator.getZ() + hri.getCardZ());
            Vector3D lonlat = CommonUtils.Mercator2lonLat(mercator);
            hri.setCardX(lonlat.getX());
            hri.setCardY(lonlat.getY());
            hri.setCardZ(lonlat.getZ());
            data.add(hri);
        }
        IotAlarmCustom iot = new IotAlarmCustom("location", "设备ID", "1", data);
        iot.setCompanyCode("hg");
        iot.setMsgId(UUID.randomUUID().toString());
        return JSON.toJSONString(iot);
    }

}
